package org.autumn.lock;

import org.autumn.structure.queue.ArrayQueue;

import java.util.concurrent.ArrayBlockingQueue;

/**
 * synchronized 修饰到普通方法上相当于锁定是当前对象
 *              修饰到静态方法上锁的是class文件
 */
public class ConcurrentProblemResolve {

    private static int res = 0;

    public static void main(String[] args) throws InterruptedException {
        Thread tom = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                synchronized (ConcurrentProblemResolve.class){
                    res++;
                }
            }
        }, "tom");

        Thread jerry = new Thread(() -> {
            for (int i = 0; i < 5000; i++) {
                synchronized (ConcurrentProblemResolve.class){
                    res--;
                }
            }
        }, "jerry");

        tom.start();
        jerry.start();

        tom.join();
        jerry.join();

        ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(1);



        System.out.println(res);
    }
}
